<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>{$lang.home}{if $ur_here} - {$ur_here} {/if}</title>
<meta name="Copyright" content="Douco Design." />
<link href="templates/public.css" rel="stylesheet" type="text/css">
<script src="images/laydate/laydate.js"></script>
<style type="text/css">
{literal}
.uploadImg{
   width:auto;
   height:auto;
   max-width:50px;
   max-height:50px;
}
{/literal}
</style>
{include file="javascript.htm"}
<script type="text/javascript">
var anchors = JSON.parse('{$live_channels_json}');
var live_status = JSON.parse('{$live_status_json}');
{literal}
$(function(){
  $("#live_channels").change(function(){
    var pullId = $(this).val();
    live_html(pullId);
  });
  init_edittime();//时间控件
})


//lay_open('live.php?rec=default&act=view_live&pullid=f5c1fdea605f4f4ca8021a267ec4bad1', '预览直播', 300)

function live_html(pullId){
    $.ajax({
        type: 'POST',
        url: 'index.php',
        data: {rec:'ajax', op:'live', ac:'channel_info', pullId:pullId},
        dataType: "json",
        success: function(rs) {
          if( "undefined" != typeof rs.data.pushConfigureInfo  ){
            var push_conf = rs.data.pushConfigureInfo;
            var pull_conf = rs.data.pullConfigureList;
            var play_url = '';
            play_url += pull_conf[0].pullUrlList[0].originPullUrl+'<br>';
            play_url += pull_conf[1].pullUrlList[0].originPullUrl+'<br>';
            play_url += pull_conf[2].pullUrlList[0].originPullUrl+'<br>';
            $('#html_record_url').html(push_conf[0].pushUrl);
            $('#html_play_url').html(play_url);
            $('#html_status').html(live_status[rs.data.channelStatus]+'&nbsp; [<a target="_blank" href="live.php?rec=default&act=view_live&play_url='+encodeURIComponent(pull_conf[0].pullUrlList[0].originPullUrl)+'">观看直播</a>]');
            $('#channel').val(rs.data.channelName);
          }else{
            $('#html_record_url').html('');
            $('#html_play_url').html('');
            $('#html_status').html('');
            $('#channel').val('');
          }
        }
    });
}
function live_stop(live_time_id, state , that){
  alert($(that).data('state'));
  var state = $(that).data('state');
   $.ajax({
        type: 'POST',
        url: 'index.php',
        data: {rec:'ajax', op:'live', ac:'stop_live', live_time_id:live_time_id, state:state},
        dataType: "json",
        success: function(rs) {
          //alert('aaa');
          if(rs.data.state == '3'){
            //alert('已停止直播');
          } 
          if(rs.data.state == '2'){
            //alert('已恢复直播');
          } 
          $('#live_state_'+live_time_id).html(live_status[rs.data.state]);
        }
    });
}
{/literal}
</script>
</head>
<body>
<div id="dcWrap">
 {include file="header.htm"}
 <div id="dcLeft">{include file="menu.htm"}</div>
 <div id="dcMain">
   {include file="ur_here.htm"}
   <div class="mainBox" style="{$workspace.height}">
    <h3> <a href="{$anchor_add_link.href}" class="actionBtn add">{$anchor_add_link.text}</a> <a href="{$anchor_link.href}" class="actionBtn">{$anchor_link.text}</a> <a href="{$live_set_link.href}" class="actionBtn">{$live_set_link.text}</a> {$ur_here}</h3>

    <!-- {if $rec eq 'default'} 列表 -->
    <div class="filter">
      <form action="live.php" method="post">
        <input name="username" class="inpMain" placeholder="用户名" value="" size="20" type="text">
        <input name="submit" class="btnGray" value="查询" type="submit">
        <input type="hidden" name="rec" value="default">
      </form>
    </div>
    <form name="action" method="post" action="live.php?rec=action">
    <table width="100%" border="0" cellpadding="8" cellspacing="0" class="tableBasic">
     <tr>
      <th width="22" align="center"><input name='chkall' type='checkbox' id='chkall' onclick='selectcheckbox(this.form)' value='check'></th>
      <th width="30" align="left">{$lang.record_id}</th>
      <th align="center">{$lang.user_username}</th>
      <th align="center">{$lang.user_nickname}</th>
      <th align="center">{$lang.channel}</th>
      <th align="center">{$lang.live_status}</th>
      <th align="center" width="10%">{$lang.add_time}</th>
      <th>{$lang.handler}</th>
     </tr>
     <!-- {foreach from=$anchor_list item=anchor} -->
     <tr>
      <td align="center"><input type="checkbox" name="checkbox[]" value="{$anchor.id}" /></td>
      <td>{$anchor.id}</td>
      <td align="center">{$anchor.username}</td>
      <td align="center">{$anchor.nickname}</td>
      <td align="center">{$anchor.channel}</td>
      <td align="center"><script>document.write(live_status[{$anchor.state}]);</script></td>
      <td align="center">{$anchor.create_time}</td>
      <td align="center" align="center">
        <a href="live.php?rec=edit&id={$anchor.id}">{$lang.edit}</a> | 
        <a href="live.php?rec=del&id={$anchor.id}">{$lang.del}</a>  
     </tr>
     <!-- {/foreach} -->
    </table>
    <div class="action">
     <select name="action" onchange="douAction()">
      <option value="0">{$lang.select}</option>
      <option value="del_all">{$lang.del}</option>
     </select>
     <input name="submit" class="btn" type="submit" value="{$lang.btn_execute}" />
    </div>
    </form>
    {include file="pager.htm"}
    <!-- {/if} -->
    
    <!-- {if $rec eq 'edit' || $rec eq 'add'} 编辑 -->
    <script>live_html('{$anchor.pullid}')</script>
    <form action="live.php?rec={if $rec eq 'edit'}update{else}insert{/if}" method="post">
     <table width="100%" border="0" cellpadding="8" cellspacing="0" class="tableBasic">
      <tr>
       <td width="100" align="right">{$lang.user_username}</td>
       <td>
        <input type="text" name="username" value="{$anchor.username}" size="40" class="inpMain"/>
       </td>
      </tr>
      <tr>
       <td width="100" align="right">{$lang.user_nickname}</td>
       <td>
        <input type="text" name="nickname" value="{$anchor.nickname}" size="40" class="inpMain"/>
       </td>
      </tr>
      <tr>
       <td width="100" align="right">{$lang.user_password}</td>
       <td>
        <input type="text" name="password" size="40" class="inpMain"/>
       </td>
      </tr>
      <tr><!--直播相关信息-->
       <td width="100" align="right">{$lang.channel}</td>
       <td>
        <select name="pullid" id="live_channels">
          <option value="">请选择</option>
          {foreach from=$live_channels item=v key=k}
         <option value="{$v.pullId}" {if $v.pullId==$anchor.pullid}selected=selected{/if}  >{$v.channelName}|{$lang.live_status_in[$v.channelStatus]}</option>
         {/foreach}
        </select>
      </td>
      </tr>
      <tr>
       <td width="100" align="right">{$lang.record_url}</td>
       <td>&nbsp;<span id="html_record_url"></span></td>
      </tr>
      <tr>
       <td width="100" align="right">{$lang.play_url}</td>
       <td>&nbsp;<span id="html_play_url"></span></td>
      </tr>
      <tr>
       <td width="100" align="right">{$lang.status}</td>
       <td>&nbsp;<span id="html_status"></span></td>
      </tr>
      <tr>
       <td width="100" align="right">{$lang.description}</td>
       <td>&nbsp;<textarea name="" cols="60" rows="4">{$anchor.description}</textarea></td>
      </tr>
      <tr>
       <td></td>
       <td>
        <input type="hidden" name="token" value="{$token}" />
        <input type="hidden" name="id" value="{$anchor.id}" />
        <input type="hidden" name="channel" id="channel" value="{$anchor.channel}" />
        <input type="submit" name="submit" class="btn" value="{$lang.btn_submit}" />
       </td>
      </tr>
     </table>
    </form>
    <!-- {/if} -->

    <!-- {if $rec eq 'config'} 编辑 -->
    <script>
      var anchors = JSON.parse('{$anchors_json}');
      {literal}
        function add_html(obj){
          var str = '';
          //if(obj == 'live'){
            str += '<div><select name="anchor_id[]">';
            str += '<option value="">选择主播</option>';
            for (i=0; i<anchors.length; i++){
              v = anchors[i];
              str += '<option value="'+v.id+'">'+v.nickname+'|'+live_status[v.state]+'</option>';
            }
            str += '</select> ';
            str += '<input name="live_start[]" placeholder="开始时间" value="" size="20" class="inpMain time-item" type="text"> - ';
            str += '<input name="live_end[]" placeholder="结束时间" value="" size="20" class="inpMain time-item" type="text">&nbsp;';
            //str += ' 直播状态 ';
            //str += '<a href="live.php?rec=edit&id=" target="_blank">编辑主播</a> ';
            str += '<img onClick="del_live(this);" src="images/icon_no.png"> ';
            str += '</div>';
          //}
          $('#'+obj+'_add_in').append(str);
          init_edittime();
        }
        function del_live(that){
          $(that).parent().remove();   
        }
      {/literal}
    </script>
    <div class="idTabs">
      <ul class="tab">
        {foreach from=$rooms key=k item=v}
        <li><a {if $v.id eq $room.id}class="selected"{/if} href="live.php?rec=config&room_id={$v.id}">{$v.name}</a></li>
        {/foreach}
      </ul>
    <div class="items">
    
    <div><!--直播设置-->
      <form enctype="multipart/form-data" action="live.php?rec=config" method="post">
      <table class="tableBasic" width="100%" cellspacing="0" cellpadding="8" border="0">
      <tbody id="ext_photo">
      <tr>
        <td align="right" width="140">直播时段设置( <a onClick="add_html('{$v.roomnumber}')" href="javascript:void(0);">增加+</a> )</td>
         <td id="{$v.roomnumber}_add_in">
            {foreach from=$room.live item=vv key=kk}
            <div>
            <select name="anchor_id[]">
              <option value="">选择主播</option>
              {foreach from=$anchors item=anchor}
              <option value="{$anchor.id}" {if $vv.anchor_id == $anchor.id}selected=selected{/if}>{$anchor.nickname}|{$lang.live_status_in[$anchor.state]}</option>
              {/foreach}
            </select>
            <input name="live_start[]" placeholder="开始时间" value="{$vv.live_start}" size="20" class="inpMain time-item" type="text"> -
            <input name="live_end[]" placeholder="结束时间" value="{$vv.live_end}" size="20" class="inpMain time-item" type="text">&nbsp; 
            <span id="live_state_{$vv.id}">{$lang.live_status_in[$vv.state]}</span>
            [<a href="live.php?rec=edit&id={$vv.anchor_id}" target="_blank">编辑主播</a>] | 
            {if in_array($vv.state,array('1','2','4'))}[<a href="javascript:void(0)" data-state='{$vv.state}' onClick="live_stop('{$vv.id}',3, this)">停止直播</a>] |{/if} 
            {if in_array($vv.state,array('3'))}[<a href="javascript:void(0)" data-state='{$vv.state}' onClick="live_stop('{$vv.id}',2, this)">恢复直播</a>] |{/if} 
            [<a href="live.php?rec=default&act=view_live&pullid={$vv.pullid}" target="_blank">在线预览</a>] 
            <img onClick="del_live(this);" src="images/icon_no.png">&nbsp;
          </div>
          {/foreach}
        </td>
      </tr>
      </tbody>
      </table>
      <table width="100%" border="0" cellpadding="8" cellspacing="0" class="tableBasic">
      <tr>
       <td width="140"></td>
       <td>
        <input type="hidden" name="token" value="{$token}" />
        <input type="hidden" name="room_id" value="{$room.id}" />
        <input type="hidden" name="rec" value="config" />
        <input type="submit" name="submit" class="btn" value="{$lang.btn_submit}" />
       </td>
      </tr>
     </table>
     </form>
    </div>
    </div>
    </div>
    <!-- {/if} -->

   </div>
 </div>
 {include file="footer.htm"}
 </div>
</body>
</html>